package com.liu.communitysystemend.module.user.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.liu.communitysystemend.module.user.domain.User;
import com.liu.communitysystemend.module.user.domain.UserDto;
import com.liu.communitysystemend.module.user.service.UserService;
import com.liu.communitysystemend.utils.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.web.bind.annotation.*;

/**
 * @author liu
 * @create 2023-02-26 19:40
 */
@RestController
@RequestMapping("/api/user")
public class UserController {
    @Autowired
    private UserService userService;

    @GetMapping("/get/{id}")
    public Result<User> getUser(@PathVariable("id")String id){
        return Result.success(userService.getUserById(id));
    }

    @ApiOperation("更新用户信息")
    @PostMapping("modify")
    public Result<User> save(@RequestBody User user) {
        return
                Result.success(userService.update(user));
    }

    @ApiOperation("添加用户信息")
    @PostMapping("add")
    public Result<User> add(@RequestBody User user){
        return Result.success(userService.add(user));
    }

    @ApiOperation("查询用户列表(分页)")
    @PostMapping("page")
    public Result<Page<User>> getPage(@RequestBody User hotelVO) {
        return Result.success(userService.getPage(hotelVO));
    }

    @GetMapping("delete/{id}")
    @ApiOperation("删除用户")
    public Result deleteById(@PathVariable("id") String id){
        return userService.deleteById(id)>0 ? Result.success():Result.failed();
    }

    @ApiOperation("查询用户列表(分页)")
    @PostMapping("getAllPage")
    public Result<Page<UserDto>> getAllPage(@RequestBody User hotelVO) {
        return Result.success(userService.getAllPage(hotelVO));
    }


    @ApiOperation("用户test")
    @GetMapping("/test")
    public Result test(){
        return Result.success(userService.test());
    }




}